package com.example.wzh.robotdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

public class MainActivity extends AppCompatActivity {

    private  String url = "https://free-api.heweather.com/v5/aqi?city=海淀&key=c45d91706110494d81b7dc282cca1076";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initData();
    }

    private void initData() {
            OkHttpUtils.get()
                    .url(url)
                    .build()
                    .execute(new StringCallback() {

                        @Override
                        public void onError(okhttp3.Call call, Exception e, int id) {
                            Log.e("TAG", "联网失败==" + e.getMessage());
                        }

                        @Override
                        public void onResponse(String response, int id) {
//                            CBean bean = new Gson().fromJson(response, CBean.class);
//                            datas = bean.getHeWeather5();
//                            if (datas != null) {
//                                String city = datas.get(0).getBasic().getCity();
//                                textView.setText(city);
//                            }
                        }
                    });
        }
}
